package com.spyz.hbase_api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.AsyncConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

public class P1_HbaseConnection_2 {
    // 声明一个静态属性
    public static Connection connection =null;
    static {
        // 1. 创建连接配置对象
        Configuration conf = new Configuration();

        // 2. 添加连接配置
        conf.set("hbase.zookeeper.quorum","master,slave1,slave2");

        // 3. 创建连接
        //  默认使用同步连接
         connection = null;
        try {
            connection = ConnectionFactory.createConnection(conf);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void closeConnection() throws IOException {

        // 判断连接是否为空
        if (connection == null) {
            return;
        }
        connection.close();
    }

    public static void main(String[] args) throws IOException {

        //直接使用创建好的连接
        System.out.println(P1_HbaseConnection_2.connection);

        closeConnection();

    }


}
